package com.shengde.jinwawaforleader.model.homePage;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shengde.jinwawaforleader.R;
import com.shengde.jinwawaforleader.base.BaseActivity;

/**
 * @author 鞠永强
 * @version $Rev$
 * @time 2017/1/16 0016 15:54
 * @des ${第三方链接的 浏览界面}
 * @updateAuthor $Author$
 * @updateDate $Date$
 * @updateDes ${TODO}
 */

public class PreviewSchoolMien extends BaseActivity {
    private static final String TAG = "PreviewSchoolMien";
    public WebView show_wv;
    private TextView tv_back; //
    private TextView tv_title;
    private TextView fill_add; //
    private LinearLayout loading_main;  //加载中..
    private String url;  //网络链接

    @Override
    public void onRoot(Bundle savedInstanceState) {
        setContentView(R.layout.activity_school_mien);

    }

    @Override
    public void initView() {
        loading_main = (LinearLayout) findViewById(R.id.loading_main);

        tv_back = (TextView) findViewById(R.id.tv_back);
        tv_title = (TextView) findViewById(R.id.tv_title);
        fill_add = (TextView) findViewById(R.id.fill_add);
        show_wv = (WebView) findViewById(R.id.show_wv);
    }

    @Override
    public void initData() {
        url = getIntent().getStringExtra("url");
        Log.i(TAG, "initData: url = " + url);
        tv_title.setText(getString(R.string.preview));
        WebSettings settings = show_wv.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setSupportZoom(false);
        settings.setBuiltInZoomControls(false);
        showWebView();
    }

    /**
     * 加载webview
     */
    private void showWebView() {
        show_wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                loading_main.setVisibility(View.GONE);
            }

        });
        show_wv.loadUrl(url);
    }

    @Override
    public void initListener() {
        tv_back.setOnClickListener(this);
    }

    @Override
    public void onWidgetClick(View view) {
        switch (view.getId()) {
            case R.id.tv_back:
                finish();
                break;
            default:
                break;
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        show_wv.stopLoading();
        show_wv.destroy();
    }
}
